package com.one.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;



    /**
 * developer 扶立伟
 *  servlet的基础类
 */
public class BaseServlet extends HttpServlet {
        private static final String PREFIX_MANAGE = "/manage/";//管理页面的前缀
        private static final String SUFFIX_MANAGE = ".jsp";//管理页面的后缀
        private static final long serialVersionUID = 1L;

        public static final String PREFIX = "/user/";//后台页面的前缀
        public static final String SUFFIX = ".jsp";//后台页面的后缀
    /**
     * 管理页面的转发方法
     * developer 扶立伟
     */
    public void dispatcher_manage(String filename, HttpServletRequest request,
                                  HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher(PREFIX_MANAGE + filename + SUFFIX_MANAGE)
                .forward(request, response);
    }

    /**
     * 获取页面指令方法
     * developer 扶立伟
     */
    public String getM(HttpServletRequest request){
        String m = request.getParameter("m");
        //若为空，默认为index
        return m==null?"index":m;
    }
        /**
         * 转发页面的方法(后台)
         * @param path 需要转发的jsp页面名称
         */
        public void dispatcher(String path, HttpServletRequest request,
                               HttpServletResponse response) throws ServletException, IOException {
            request.getRequestDispatcher(PREFIX+path+SUFFIX).forward(request, response);
        }

}
